package com.koo.modules.sale.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.koo.common.utils.MyStrUtil;
import com.koo.common.utils.PageUtils;
import com.koo.common.utils.Query;
import com.koo.modules.sale.dao.SaleAdjustPriceDetailDao;
import com.koo.modules.sale.entity.SaleAdjustPriceDetailEntity;
import com.koo.modules.sale.service.SaleAdjustPriceDetailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class SaleAdjustPriceDetailServiceImpl extends ServiceImpl<SaleAdjustPriceDetailDao, SaleAdjustPriceDetailEntity> implements SaleAdjustPriceDetailService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        Object key = params.get("key");
        LambdaQueryWrapper<SaleAdjustPriceDetailEntity> queryWrapper = new LambdaQueryWrapper<>();
//        queryWrapper.like(MyStrUtil.isNotEmpty(key), SaleAdjustPriceDetailEntity::getName, key)
//                  .or().eq(MyStrUtil.isNotEmpty(key), SaleAdjustPriceDetailEntity::getCode, key);

        IPage<SaleAdjustPriceDetailEntity> page = this.page(
                new Query<SaleAdjustPriceDetailEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

    @Override
    public List<SaleAdjustPriceDetailEntity> listByStoreId(Long storeId) {
        LambdaQueryWrapper<SaleAdjustPriceDetailEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MyStrUtil.isNotEmpty(storeId), SaleAdjustPriceDetailEntity::getStoreId, storeId);
        return this.list(wrapper);
    }

    @Override
    public List<SaleAdjustPriceDetailEntity> listByAdjustPriceId(String adjustPriceId) {
        LambdaQueryWrapper<SaleAdjustPriceDetailEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MyStrUtil.isNotEmpty(adjustPriceId), SaleAdjustPriceDetailEntity::getAdjustPriceId, adjustPriceId);
        return this.list(wrapper);
    }
}